<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Vue属性和方法</title>
	<script type="text/javascript" src="js/vue.js"></script>
</head>
<body>
	<div class="container">
		<input type="text" v-model="msg">
		{{msg}}
		{{user.address}}{{user.age}}
		<h2 ref="hello">你好</h2>
		<hr>
		<h2 ref="title">标题：{{tom}}</h2>
		
		<button @click="addUser">添加use属性</button>
		<button @click="deleteUser">删除user属性</button>
	</div>
	<script>
		var vm = new Vue({
			// el:'.container',
			data:{
				msg:'welcome to Vue!',
				tom:'tom',
				user:{
					usename:'小明',
					age:21
				}
			},
			name:'小明',
			age:20,
			methods:{
				addUser(){
					// this.user.address='北京朝阳';
					this.$set(this.user,'address','北京朝阳');
				},
				deleteUser(){
					this.$delete(this.user,'age');
				}
			},
			watch:{
				user(newValue,oldValue){
					console.log("user的值变化了,新值="+newValue.address+",老值="+oldValue.address)
				},
				deep:true,
				msg(newValue,oldValue){
					console.log("msg的值变化了,新值="+newValue+",老值="+oldValue)
				}
			}
		}).$mount('.container');

		//vm.$destroy();//销毁实例

		console.log(vm.$el);//获取Vue实例关联的元素
		vm.$el.style.color="red";

		console.log(vm.$data.msg);//获取Vue实例的数据对象data

		console.log(vm.$options.name);//获取自定义属性

		console.log(vm.$refs.hello);//获取所有添加ref属性的元素

		vm.tom="汤姆";
		console.log(vm.$refs.title.textContent);
		vm.$nextTick(function(){
			console.log(vm.$refs.title.textContent);
		})

	</script>
</body>
</html>